package zillow.api.results;

/**
 * ConnectSQLite.java
 */

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;


/**
 * @author www.javaworkspace.com
 * 
 */
public class ConnectSQLite {
	public static void main(String[] args) throws ClassNotFoundException, SQLException {

		Connection connection = null;
		ResultSet rs = null;
		Statement stmt = null;

		try {
			Class.forName("org.sqlite.JDBC");
			//Context ctx = new InitialContext();
			//DataSource ds = (DataSource) ctx.lookup("jdbc:sqlite:/Library/cubesql/databases/homefinders.db");
			connection = DriverManager.getConnection("jdbc:sqlite:homefinders.db");
			int iTimeout = 30;
			//String sMakeTable = "CREATE TABLE login (username varchar(20) primary key, pw varchar(10) not null)";
			//String sMakeInsert = "INSERT INTO login VALUES('Annie','12345')";
			String sMakeSelect = "SELECT username from login";
			stmt = connection.createStatement();
			try {
				stmt.setQueryTimeout(iTimeout);
				//stmt.executeUpdate( sMakeTable );
				//stmt.executeUpdate( sMakeInsert );
				rs = stmt.executeQuery(sMakeSelect);
				try {
				while(rs.next())
				{
				String sResult = rs.getString("username");
				System.out.println(sResult);
				}
				} finally {
				    try { rs.close(); } catch (Exception ignore) {}
				}
				} finally {
				    try { stmt.close(); } catch (Exception ignore) {}
				}
				} finally {
				    try { connection.close(); } catch (Exception ignore) {}
				}
				}
}
